package com.my.code.threadpool;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * 简单测试我的线程池
 *
 * @author zzl
 * @date 2020/10/14
 */
public class TestThreadPool {

    public static void main(String[] args) throws InterruptedException {
        ThreadPool<Runnable> threadPool = new MyThreadPool(5);
        Random r = new Random();
        for (int i = 0; i < 10; i++) {
            int finalI = i;
            threadPool.execute(() -> {
                try {
                    TimeUnit.MILLISECONDS.sleep(r.nextInt(100));
                    System.out.println(Thread.currentThread().getName() + ", id=" + finalI + " running done");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        }

        TimeUnit.SECONDS.sleep(20);
        threadPool.shutdown();
    }

}
